package com.gzz.controller;


import com.gzz.common.R;
import com.gzz.pojo.Activity;
import com.gzz.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 周佳成
 * @since 2023-11-21
 */
@Slf4j
@RestController
@RequestMapping("/api/activity")
public class ActivityController {
    @Autowired
    ActivityService activityService;
    @GetMapping("/list")
    public R<List<Activity>> getAll(@RequestParam(name = "curPage")Integer curPage,@RequestParam(name = "pageSize")Integer pageSize){
        List<Activity> activityList = activityService.list();
        Integer num = activityList.size();
        Integer end = (curPage+1)*pageSize;
        if(num<(curPage+1)*pageSize){
            end = num;
        }
        activityList.subList(curPage*pageSize,end-1);
        for (Activity activity : activityList) {
            activity.setTotNum(num);
        }
        log.info("完成查询返回数组");
        return R.success(activityList);
    }
    @GetMapping("/detail")
    public R<Activity> getDetail(@RequestParam(name = "scId") Long scId)
    {
        return R.success(activityService.getById(scId));
    }
}